package ms.jasim.model.editor.actions;

import java.io.IOException;

import ms.jasim.framework.test.GenTestFilePattern1;
import ms.jasim.framework.test.GenTestFilePattern2;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;

public class GenerateTestProblemAction extends Action implements IAction {
	
	public GenerateTestProblemAction() {
		super("Generate test problem");
	}
	
	@Override
	public void run() {
		//generateTestPattern1();
		generateTestPattern2();
	}

	protected void generateTestPattern2() {
		GenTestFilePattern2 gen = new GenTestFilePattern2();
		for (int i = 1; i <= 20; i++) {
			System.out.println("Number of trees: " + i);
			System.out.println("--------------------------");
			gen.createElementTree("T" + i + "_");
			try {
				gen.save("mt_" + i);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		GenTestFilePattern2 gen2 = new GenTestFilePattern2();
		gen2.createElementTree("G");
		for (int i = 4; i <= 24; i++, gen2.increaseLevel()) {
			try {
				gen2.save("st_" + i);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	protected void generateTestPattern1() {
		for (int fo = 2; fo <= 12; fo ++)
			for (int N = 2; N <= 7; N ++) {
				double num = (Math.pow(fo, N + 1) - 1)/(fo - 1);
				if (num <400) {
					System.out.printf("FO = %d, N = %d\r\n", fo, N);
					System.out.println("--------------------------");
					try {
						if (new GenTestFilePattern1(1, 10, -1, N, fo).save("st") >= 400)
							break;
					} catch (IOException e) {
						break;
					}
				}
			}
		for (int t = 1;; t++) {
			System.out.println("Number of tree = " + t);
			try {
				if (new GenTestFilePattern1(t, 10, -1, 3, 3).save("mt_" + t) >= 400)
					break;
			} catch (IOException e) {
				break;
			}
		}
		System.out.println("Done.");
	}
}
